package cn.funeralobjects.dictms.web.mapper;

import cn.funeralobjects.common.web.controller.converter.ModelMapper;
import cn.funeralobjects.dictms.entity.EDictRelate;
import cn.funeralobjects.dictms.model.DictRelate;
import cn.funeralobjects.dictms.web.model.MDictRelate;
import cn.funeralobjects.dictms.web.model.VDictRelate;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author FuneralObjects
 * Create date: 2020/6/9 2:45 PM
 */
@Mapper(componentModel = "spring")
public interface DictRelateMapper extends ModelMapper<MDictRelate, DictRelate, EDictRelate, VDictRelate> {

    @Mappings({
            @Mapping(target = "headDictId", source = "headDict.id")
    })
    @Override
    VDictRelate toVo(EDictRelate eDictRelate);

    @Override
    default List<VDictRelate> toVo(List<EDictRelate> eDictRelates) {
        if (eDictRelates == null) {
            return null;
        }
        return eDictRelates.stream().map(this::toVo).collect(Collectors.toList());
    }

    @Mappings({
            @Mapping(target = "headDict.id", source = "headDictId")
    })
    @Override
    EDictRelate toEntity(VDictRelate vDictRelate);

    @Override
    default List<EDictRelate> toEntity(List<VDictRelate> vDictRelates) {
        if (vDictRelates == null) {
            return null;
        }
        return vDictRelates.stream().map(this::toEntity).collect(Collectors.toList());
    }
}
